package com.wn.class30.cotroller.weixin;

import com.wn.class30.entity.Business;
import com.wn.class30.service.WXBussinessService;
import com.wn.class30.tools.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.weixin4j.Weixin;
import org.weixin4j.WeixinException;
import org.weixin4j.model.js.Ticket;
import org.weixin4j.model.js.WxConfig;
import org.weixin4j.spring.WeixinTemplate;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

@RestController
@Api(value = "附近门店",tags = "附近门店")
@RequestMapping(value = "/weixin")
@Validated
@Slf4j
public class WxBussinessController {
    @Resource
    private WeixinTemplate weixinTemplate;
    @Resource
    private WXBussinessService wxBussinessService;
    @GetMapping(value = "/getTicket")
    @ApiOperation(value="查询js-sdk关键参数",notes ="查询js-sdk关键参数" )
    public Result getTicket(HttpServletRequest req,String ur) throws WeixinException {
        WxConfig wxConfig = weixinTemplate.js().getWxConfig(ur);
        return new Result("200","success",wxConfig,null);
    }
    @ApiOperation(value="查询附近门店",notes ="查询附近门店" )
    @GetMapping(value = "/queryBussiness")
    public Result queryBussinesses(@Valid @NotNull Double latitude,@Valid @NotNull Double longitude) throws Exception {
        log.info(String.valueOf(latitude));
        log.info(String.valueOf(longitude));
        List<Business> businesses = wxBussinessService.queryBusinesses(latitude, longitude);
        log.info(String.valueOf(businesses));
        System.out.println(businesses);
        return new Result("200","success",null,businesses);
    }
}
